package com.huluobo.a2112mvvmdouyindemo.like;

import androidx.lifecycle.MutableLiveData;

import com.huluobo.mvvm_base.bean.LikeBeanResult;
import com.huluobo.mvvm_base.bean.LikeVideoBeanResult;
import com.huluobo.mvvm_base.model.BaseRepo;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by LC on 2024/4/10.
 */
public class LikeRepo extends BaseRepo {
    public void getLikeVideos(MutableLiveData<LikeVideoBeanResult> success, MutableLiveData<String> failed) {
        apiService.getLikeVideoList()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<LikeVideoBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(LikeVideoBeanResult likeVideoBeanResult) {
                        success.setValue(likeVideoBeanResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void cancelLike(int videoId, MutableLiveData<LikeBeanResult> success, MutableLiveData<String> failed) {
        apiService.noLikeVideo(videoId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<LikeBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(LikeBeanResult likeBeanResult) {
                        success.setValue(likeBeanResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
